package com.dgty.dg_common.base

import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.dgty.dg_common.network.ExceptionHandle
import kotlinx.coroutines.CoroutineExceptionHandler

/**
 * Title: MVVMUtil.kt
 * Description:
 * Created DateTime: 2023-02-08
 * Created by xxl.
 */
object MVVMUtil {

    private val defNetException = CoroutineExceptionHandler { _, throwable ->
        val exception = ExceptionHandle.handleException(throwable)
        LogUtils.eTag("接口", ""+exception.code + exception.errMsg + exception.message)
        ToastUtils.showShort(exception.errMsg)
    }

    val netException: CoroutineExceptionHandler
        get() = customNetException ?: defNetException


    private var customNetException: CoroutineExceptionHandler? = null


    fun setNetException(netException: CoroutineExceptionHandler) = apply {
        customNetException = netException
    }

}